﻿IF EXISTS (SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = 'puestoDelete')
	BEGIN
		DROP  Procedure  puestoDelete
	END
GO


CREATE PROCEDURE [dbo].[puestoDelete] 
	@id INT
AS	
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	IF EXISTS(	SELECT Id 
				FROM Lit_Operario 
				WHERE PuestoId = @id
				AND Activo = 1) BEGIN
		SELECT 0;
					
	END
	ELSE BEGIN
		UPDATE Lit_Puesto SET Activo = 0 WHERE Id = @id;
		SELECT 1;
	END
	
END
GO